using System;
using System.Drawing;
using System.Windows.Forms;

namespace PinTuGame
{
    public partial class SettingsForm : Form
    {
        public bool SoundEnabled { get; private set; }
        public bool MusicEnabled { get; private set; }
        public bool AutoSaveEnabled { get; private set; }
        public int HintLimit { get; private set; }

        private CheckBox soundCheckBox;
        private CheckBox musicCheckBox;
        private CheckBox autoSaveCheckBox;
        private NumericUpDown hintLimitNumeric;

        public SettingsForm(bool currentSoundEnabled, bool currentMusicEnabled, bool currentAutoSaveEnabled, int currentHintLimit)
        {
            SoundEnabled = currentSoundEnabled;
            MusicEnabled = currentMusicEnabled;
            AutoSaveEnabled = currentAutoSaveEnabled;
            HintLimit = currentHintLimit;

            InitializeComponents();
        }

        private void InitializeComponents()
        {
            this.Text = "游戏设置";
            this.Size = new Size(400, 350);
            this.StartPosition = FormStartPosition.CenterParent;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;

            // 创建主面板
            TableLayoutPanel mainPanel = new TableLayoutPanel
            {
                Dock = DockStyle.Fill,
                ColumnCount = 1,
                RowCount = 3,
                Padding = new Padding(10),
                RowStyles = 
                {
                    new RowStyle(SizeType.Percent, 100),
                    new RowStyle(SizeType.Absolute, 10),
                    new RowStyle(SizeType.Absolute, 40)
                }
            };

            // 设置选项面板
            Panel optionsPanel = new Panel
            {
                Dock = DockStyle.Fill,
                AutoScroll = true
            };

            int yOffset = 20;

            // 音效设置
            Label soundLabel = new Label
            {
                Text = "音效设置",
                Location = new Point(20, yOffset),
                Font = new Font("微软雅黑", 12, FontStyle.Bold),
                AutoSize = true
            };
            optionsPanel.Controls.Add(soundLabel);
            yOffset += 30;

            soundCheckBox = new CheckBox
            {
                Text = "启用音效",
                Location = new Point(30, yOffset),
                Checked = SoundEnabled,
                Font = new Font("微软雅黑", 10)
            };
            optionsPanel.Controls.Add(soundCheckBox);
            yOffset += 40;

            musicCheckBox = new CheckBox
            {
                Text = "启用背景音乐",
                Location = new Point(30, yOffset),
                Checked = MusicEnabled,
                Font = new Font("微软雅黑", 10)
            };
            optionsPanel.Controls.Add(musicCheckBox);
            yOffset += 50;

            // 游戏设置
            Label gameLabel = new Label
            {
                Text = "游戏设置",
                Location = new Point(20, yOffset),
                Font = new Font("微软雅黑", 12, FontStyle.Bold),
                AutoSize = true
            };
            optionsPanel.Controls.Add(gameLabel);
            yOffset += 30;

            autoSaveCheckBox = new CheckBox
            {
                Text = "自动保存游戏进度",
                Location = new Point(30, yOffset),
                Checked = AutoSaveEnabled,
                Font = new Font("微软雅黑", 10)
            };
            optionsPanel.Controls.Add(autoSaveCheckBox);
            yOffset += 40;

            Label hintLabel = new Label
            {
                Text = "提示次数限制:",
                Location = new Point(30, yOffset),
                Font = new Font("微软雅黑", 10),
                AutoSize = true
            };
            optionsPanel.Controls.Add(hintLabel);
            yOffset += 25;

            hintLimitNumeric = new NumericUpDown
            {
                Location = new Point(30, yOffset),
                Width = 80,
                Minimum = 0,
                Maximum = 10,
                Value = HintLimit,
                Font = new Font("微软雅黑", 10)
            };
            optionsPanel.Controls.Add(hintLimitNumeric);
            yOffset += 30;

            Label hintDescLabel = new Label
            {
                Text = "(0表示无限制)",
                Location = new Point(120, yOffset),
                Font = new Font("微软雅黑", 8),
                ForeColor = Color.Gray,
                AutoSize = true
            };
            optionsPanel.Controls.Add(hintDescLabel);

            // 按钮面板
            Panel buttonPanel = new Panel
            {
                Dock = DockStyle.Fill
            };

            Button okButton = new Button
            {
                Text = "确定",
                Size = new Size(80, 30),
                Location = new Point(200, 5),
                DialogResult = DialogResult.OK,
                Font = new Font("微软雅黑", 10)
            };
            okButton.Click += OkButton_Click;
            buttonPanel.Controls.Add(okButton);

            Button cancelButton = new Button
            {
                Text = "取消",
                Size = new Size(80, 30),
                Location = new Point(290, 5),
                DialogResult = DialogResult.Cancel,
                Font = new Font("微软雅黑", 10)
            };
            buttonPanel.Controls.Add(cancelButton);

            Button resetButton = new Button
            {
                Text = "重置默认",
                Size = new Size(80, 30),
                Location = new Point(20, 5),
                Font = new Font("微软雅黑", 10)
            };
            resetButton.Click += ResetButton_Click;
            buttonPanel.Controls.Add(resetButton);

            mainPanel.Controls.Add(optionsPanel, 0, 0);
            mainPanel.Controls.Add(buttonPanel, 0, 2);

            this.Controls.Add(mainPanel);
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            SoundEnabled = soundCheckBox.Checked;
            MusicEnabled = musicCheckBox.Checked;
            AutoSaveEnabled = autoSaveCheckBox.Checked;
            HintLimit = (int)hintLimitNumeric.Value;
        }

        private void ResetButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要重置为默认设置吗？", "确认重置", 
                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                soundCheckBox.Checked = true;
                musicCheckBox.Checked = true;
                autoSaveCheckBox.Checked = false;
                hintLimitNumeric.Value = 3;
            }
        }
    }
} 